﻿using System.Web.UI;
using System.Web.UI.WebControls;

namespace TemplateFoundation.UI.WebControls
{
    /// <summary>
    /// Used to add a list box control when creating user interfaces for the EPiServer UI
    /// </summary>
    public class ListBox : PagePropertyStyleControlBase
    {
        private System.Web.UI.WebControls.ListBox _listBox = new System.Web.UI.WebControls.ListBox();

        /// <summary>
        /// Creates a new ListBox control
        /// </summary>
        public ListBox()
        {
            _listBox.Attributes.Add("style","width: 246px");
        }

        /// <summary>
        /// Creates the property control to render
        /// </summary>
        public override Control CreatePropertyControl()
        {
            return _listBox;
        }

        /// <summary>
        /// Provides access to embedded ListBox control property
        /// </summary>
        public ListItemCollection Items
        {
            get
            {
                return _listBox.Items;
            }
        }

        /// <summary>
        /// Provides access to embedded ListBox control property
        /// </summary>
        public int SelectedIndex
        {
            get
            {
                return _listBox.SelectedIndex;
            }
            set
            {
                _listBox.SelectedIndex = value;
            }
        }

        /// <summary>
        /// Provides access to embedded ListBox control property
        /// </summary>
        public string SelectedValue
        {
            get
            {
                return _listBox.SelectedValue;
            }
            set
            {
                _listBox.SelectedValue = value;
            }
        }

        /// <summary>
        /// Provides access to embedded ListBox control property
        /// </summary>
        public ListSelectionMode SelectionMode
        {
            get
            {
                return _listBox.SelectionMode;
            }
            set
            {
                _listBox.SelectionMode = value;
            }
        }

        /// <summary>
        /// Provides access to embedded ListBox control property
        /// </summary>
        public string DataMember
        {
            get
            {
                return _listBox.DataMember;
            }
            set
            {
                _listBox.DataMember = value;
            }
        }

        /// <summary>
        /// Provides access to embedded ListBox control property
        /// </summary>
        public object DataSource
        {
            get
            {
                return _listBox.DataSource;
            }
            set
            {
                _listBox.DataSource = value;
            }
        }

        /// <summary>
        /// Provides access to embedded ListBox control property
        /// </summary>
        public string DataSourceID
        {
            get
            {
                return _listBox.DataSourceID;
            }
            set
            {
                _listBox.DataSourceID = value;
            }
        }

        /// <summary>
        /// Provides access to embedded ListBox control property
        /// </summary>
        public IDataSource DataSourceObject
        {
            get
            {
                return _listBox.DataSourceObject;
            }
        }

        /// <summary>
        /// Provides access to embedded ListBox control property
        /// </summary>
        public string DataTextField
        {
            get
            {
                return _listBox.DataTextField;
            }
            set
            {
                _listBox.DataTextField = value;
            }
        }

        /// <summary>
        /// Provides access to embedded ListBox control property
        /// </summary>
        public string DataTextFormatString
        {
            get
            {
                return _listBox.DataTextFormatString;
            }
            set
            {
                _listBox.DataTextFormatString = value;
            }
        }

        /// <summary>
        /// Provides access to embedded ListBox control property
        /// </summary>
        public string DataValueField
        {
            get
            {
                return _listBox.DataValueField;
            }
            set
            {
                _listBox.DataValueField = value;
            }
        }

        /// <summary>
        /// Provides access to embedded ListBox control property
        /// </summary>
        public int[] GetSelectedIndices()
        {
            return _listBox.GetSelectedIndices();
        }
    }
}
